<?php
namespace app\admin\model;
use think\Model;
class User extends Model{


    //登录判断
    public function index($username,$password){

        $admin=$this->where('username',$username)->find();
        if ($admin){
            $admin=$admin->toArray();
        }
        if ($admin){//如果用户名存在

            if (md5($password)===$admin['password']){


                $array=[
                    'code'=>$admin['id'],
                ];
                //return $admin['id'];//密码正确,返回用户id
                return $array;
            }else{
                $array=[
                    'code'=>-3,
                ];
                return $array;
                //return -3;//密码错误
            }

        }else{
            $array=[
                'code'=>-2,
            ];
            return $array;

            //return -2;//用户名不存在
        }

    }


    //账号密码修改
    public function user_update($id,$username,$password){
        $this->where("id","=",$id)->update([
           "username"=>$username,
           "password"=>$password
        ]);

    }


    //输出账号
    public function user_show(){
        $result=$this->where("1=1")->field(['id',"username"])->find();
        if ($result){
            $result=$result->toArray();
        }
        return $result;
    }


}
